//
//
//  @ Project : AgriMarketSystem
//  @ Date : 18/10/2013
//  @ Author : NTT
//
//
using System.Collections.Generic;
using System.Linq;
namespace AgriMarketService
{
    public class UserAccount
    {
        private string userName;
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        private string password;
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        //private int userId;
        //public int UserId
        //{
        //    get { return userId; }
        //    set { userId = value; }
        //}
        private TypeOfUser typeOfUser;

        public TypeOfUser TypeOfUser
        {
            get { return typeOfUser; }
            set { typeOfUser = value; }
        }
        private User user;
        public User User
        {
            get { return user; }
            set { user = value; }
        }
        public static UserAccount GetUserAccountByUserName(string userName)
        {
            List<UserAccount> allUserAccounts = GetAllUserAccounts();
            UserAccount userAccount = (from tempUserAccount in allUserAccounts where tempUserAccount.userName == userName select tempUserAccount).FirstOrDefault();
            return userAccount;
        }
        public static bool CheckLogIn(string userName, string password)
        {
            List<UserAccount> allUserAccounts = GetAllUserAccounts();
            UserAccount userAccount = (from tempUserAccount in allUserAccounts where tempUserAccount.userName == userName && tempUserAccount.password==password select tempUserAccount).FirstOrDefault();
            return userAccount != null;
        }
        public static List<UserAccount> GetAllUserAccounts()
        {
            return new List<UserAccount>() {
                new UserAccount(){userName="user1",password="123456",user=User.GetUser(1),typeOfUser=TypeOfUser.GetTypeById(1)},
                new UserAccount(){userName="user2",password="123456",user=User.GetUser(2),typeOfUser=TypeOfUser.GetTypeById(2)},
                new UserAccount(){userName="user3",password="123456",user=User.GetUser(3),typeOfUser=TypeOfUser.GetTypeById(3)},
                new UserAccount(){userName="user4",password="123456",user=User.GetUser(4),typeOfUser=TypeOfUser.GetTypeById(4)},
                new UserAccount(){userName="user5",password="123456",user=User.GetUser(4),typeOfUser=TypeOfUser.GetTypeById(5)},
            };
        }
        public static string GetImage(string userAccName)
        {
            UserAccount userAcc = GetUserAccountByUserName(userAccName);
            return System.Configuration.ConfigurationManager.AppSettings["UserServiceURL"] + userAcc.user.Image;
        }
    }
}